import Vue from 'vue'
import router from './router'
import ElementUI from 'element-ui'
Vue.use(ElementUI);
import {
    setlsItem,
    getlsItem,
    clearls
} from '@/utils/lstorage'
import Nprogress from "nprogress"
import 'nprogress/nprogress.css'
router.beforeEach((to, from, next) => {
    Nprogress.start()
    setlsItem('name', 'admin')
    console.log(to.path);
    console.log(getlsItem('name'));
    console.log(getlsItem('name') != null)
    if (getlsItem('name') != null && to.path != '/login') { // 如果已登录直接跳转
        if (to.path === '/login') { // 如果在已登录状态下跳转登录页强制跳转至index
            next('/')
        } else {
            next();

        }

    } else {
        if (to.path === '/login') { // 如果是登录页面路径，就直接next()
            next();
        } else { // 否则强制跳转至登录页面
            next('/login');

        }
    }
    Nprogress.done()

})